package com.cssw.fyzb.core.dao.acct;

import com.cssw.fyzb.core.model.dodb.RnbExchangeFDef;
import com.cssw.fyzb.core.model.dodb.RnbExchangeGzDef;
import com.cssw.fyzb.core.model.dodb.YExchangeFDef;
import com.ydn.dbframe.plugin.activerecord.Page;
import com.ydn.dbframe.plugin.activerecord.parse.SqlParse;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author zhouxu
 * @create 2020-12-21 16:04
 */
@Repository
public class AcctExtDaoImpl implements AcctExtDao {

    @Override
    public List<RnbExchangeFDef> listRnbExchangeFDef() {
        String sql = "select * from t_rnb_exchange_f_def where state = '1' ";
        return RnbExchangeFDef.dao.find(sql);
    }

    @Override
    public RnbExchangeFDef findRnbExchangeFDefById(Long rfId) {
        return RnbExchangeFDef.dao.findById(rfId);
    }

    @Override
    public Page<RnbExchangeFDef> getAllDef(Map param, int page, int limit) {
        SqlParse sqlParse = new SqlParse(param);
        sqlParse.addSQL("select * from t_rnb_exchange_f_def where state = '1'");
        return RnbExchangeFDef.dao.paginate(page, limit, sqlParse);
    }

    @Override
    public  void delete(Long yfId,Long userId){
        RnbExchangeFDef rnbExchangeFDef = new RnbExchangeFDef();
        rnbExchangeFDef.setRfId(yfId);
        rnbExchangeFDef.setUpdateOperId(userId);
        rnbExchangeFDef.setUpdateTime(new Date());
        rnbExchangeFDef.setState("0");
        rnbExchangeFDef.update();
    }

    @Override
    public void update(Long yfId, BigDecimal rnb, BigDecimal fCoin, Long userId){
        RnbExchangeFDef rnbExchangeFDef = new RnbExchangeFDef();
        rnbExchangeFDef.setRfId(yfId);
        rnbExchangeFDef.setUpdateOperId(userId);
        rnbExchangeFDef.setUpdateTime(new Date());
        rnbExchangeFDef.setFCoin(fCoin);
        rnbExchangeFDef.setRnb(rnb);
        rnbExchangeFDef.update();
    }

    @Override
    public void  add( BigDecimal rnb, BigDecimal fCoin, Long userId){
        RnbExchangeFDef rnbExchangeFDef = new RnbExchangeFDef();
        rnbExchangeFDef.setCreateOperId(userId);
        rnbExchangeFDef.setCreateTime(new Date());
        rnbExchangeFDef.setFCoin(fCoin);
        rnbExchangeFDef.setRnb(rnb);
        rnbExchangeFDef.setState("1");
        rnbExchangeFDef.save();
    }

    @Override
    public List<RnbExchangeGzDef> listRnbExchangeGzDef() {
        String sql = "select * from t_rnb_exchange_gz_def where state = '1' ";
        return RnbExchangeGzDef.dao.find(sql);
    }

    @Override
    public RnbExchangeGzDef findRnbExchangeGzDefById(Long rgId) {
        return RnbExchangeGzDef.dao.findById(rgId);
    }

}
